package com.contextor.magiccards.services.user.impl;

import com.contextor.magiccards.dao.user.UserDao;
import com.contextor.magiccards.model.errors.dao.ObjectNotFoundException;
import com.contextor.magiccards.model.user.User;
import com.contextor.magiccards.services.BaseService;
import com.contextor.magiccards.services.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * User: Sergey
 * Date: 14.03.2011 22:35:03
 */
@Service
class UserServiceImpl extends BaseService<User, UserDao> implements UserService {

    @Autowired
    UserServiceImpl(UserDao dao) {
        super(dao);
    }

    public User findByUid(int shardId, String uid) {
        return dao.getById(shardId, uid);
    }

    public User loadByUid(int shardId, String uid) throws ObjectNotFoundException {
        final User user = dao.getById(shardId, uid);
        if (user == null) {
            throw new ObjectNotFoundException("shardId=" + shardId + " uid=" + uid);
        }
        return user;
    }
}
